version: '3.8'

services:
  web:
    build: ./src
    command: |
      bash -c 'while !</dev/tcp/db/5432; do sleep 1; done; uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 8000'
    volumes:
      - ./src/:/usr/src/app/
    ports:
      - 8000:8000
    environment:
      - DATABASE_URL=postgresql://fastapi_recipes:fastapi_recipes@db/fastapi_recipes_dev
  db:
    image: postgres:15.1-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    expose:
      - 5432
    environment:
      - POSTGRES_USER=fastapi_recipes
      - POSTGRES_PASSWORD=fastapi_recipes
      - POSTGRES_DB=fastapi_recipes_dev

volumes:
  postgres_data: